package com.ls.fw.data.search.impl.solrj.statement;

import com.ls.fw.data.dao.DataDaoConstant;
import com.ls.fw.data.statement.Delete;
import com.ls.fw.data.visitor.DeleteVisitor;


public class DeleteParser extends BaseParser implements DeleteVisitor{

	boolean condition = false;
	
	
	
	public DeleteParser(Delete delete) {
		this.visit(delete);
	}
	
	
	@Override
	public void visit(Delete delete) {
		if(delete.getTable()!=null){
			StringBuilder sb = new StringBuilder();
			if(delete.hasWhere()){
				WhereParser w = new WhereParser(delete.getTable(),delete.getWhere());
				w.parse(query);
				if(!w.isHasMethod()){
					String[] strs = query.getFilterQueries();
					int index = 0;
					for (String string : strs) {
						if(index>0){
							sb.append(" AND ");
						}
						sb.append(string);
						index++;
					}
				}
			}else{
				sb.append(DataDaoConstant.DEFAULT_TABLE_FIELD+":"+delete.getTable().getFullName());
			}
			query.setQuery(sb.toString());
			condition = true;
		}
	}

	
	public boolean hasCondition(){
		return condition;
	}
	
}
